<?php

class LoginModel extends Model
{
	public function DoLogin( $username, $password )
	{
		$password = sha1( $password );
		
		$stmt = $this->db->prepare( "SELECT UserID, Username, Email FROM Users WHERE Username = ? && Password = UNHEX(?)" );
		$stmt->bind_param( "ss", $username, $password );
		$stmt->execute();
		$stmt->bind_result( $row_id, $row_name, $row_email );
		$stmt->fetch();
		if ( $row_id )
		{
			Auth::SetUser( $row_id, $row_name, $row_email );
		}
		$stmt->close();
		
		return Auth::IsLoggedIn();
	}
	
	public function DoLogout()
	{
		Auth::LogoutUser();
	}
}
